{extend name="admin/base" /}
{block name="resources"/}{/block}
{block name="main"}
<input type="hidden" id="shop_id" value="{$shop_id}">
<input type="hidden" id="website_id" value="{$website_id}">
<div class="mb-20 flex flex-pack-justify">
    <div class=""></div>
    <div class="input-group search-input-group">
        <input type="text" class="form-control" id="search_text" placeholder="请输入物流公司名称或编号">
        <span class="input-group-btn "><a class="btn btn-primary search_to">搜索</a></span>
    </div>
</div>
<table class="table v-table">
	<thead>
	<tr>
		<th>物流公司</th>
		<th>物流编号</th>
		<!--<th>联系电话</th>-->
		<!--<th>是否默认</th>-->
		<!--<th>排序</th>-->
		<th>是否启用</th>
		<th class="col-md-2 pr-14 operationLeft">操作</th>
	</tr>
	</thead>
	<tbody class="trs" id="list">
	</tbody>
</table>
<div class="page clearfix">
	<div class="M-box3 m-style fr">
	</div>
</div>
{/block}
{block name="script"}
<!--<script src="ADMIN_JS/express/express_company.js"></script>-->
<script type="text/javascript">
  require(['utilAdmin'], function (utilAdmin) {

	$(function () {
		LoadingInfo(1);

		$("#list").on('click', '.disabled-company', function () {
			$(".tooltip.fade.top.in").remove();
			$.ajax({
				type: "POST",
				url: __URL(ADMINMAIN + "/express/setUnused"),
				data: {
					"co_id": $(this).attr('data-co-id')
				},
				success: function (data) {
					if (data['code'] > 0) {
						utilAdmin.message(data['message'],'success', LoadingInfo($("#page_index").val()));
					} else {
						utilAdmin.message(data['message'],'danger');
					}
				}
			})
		})

		$("#list").on('click', '.able-company', function () {
			$(".tooltip.fade.top.in").remove();
			$.ajax({
				type: "POST",
				url: __URL(ADMINMAIN + "/express/setUse"),
				data: {
					"co_id": $(this).attr('data-co-id')
				},
				success: function (data) {
					if (data['code'] > 0) {
						utilAdmin.message(data['message'], 'success', LoadingInfo($("#page_index").val()));
					} else {
						utilAdmin.message(data['message'], 'danger');
					}
				}
			})
		})
	})
	var shop_id = $("#shop_id").val();
	var website_id = $("#website_id").val()

	function LoadingInfo(page_index) {
		var search_text = $("#search_text").val();
		$("#page_index").val(page_index);
		$.ajax({
			type: "post",
			url: __URL(ADMINMAIN + "/express/expresscompany"),
			data: {
				"page_index": page_index,
				"page_size": $("#showNumber").val(),
				"search_text": search_text
			},
			success: function (data) {
				var html = '';

				//     <th>物流公司</th>
				//     <th>物流编号</th>
				//     <th>是否启用</th>
				//     <th>操作</th>
				if (data["data"].length > 0) {
					for (var i = 0; i < data["data"].length; i++) {
						var curr = data['data'][i];
						html += '<tr>';
						html += '<td>' + curr.company_name + '</td>';
						html += '<td>' + curr.express_no + '</td>';
						// html += '<td>' + curr.phone + '</td>';
						// if (curr.is_default == 1) {
						//     html += '<td>是</td>';
						// } else {
						//     html += '<td>否</td>';
						// }
						// html += '<td>' + curr.orders + '</td>';
						if (curr.shop_id == shop_id) {
							html += '<td><span class="label label-success">是</span></td>';
						} else {
							html += '<td><span class="label label-danger">否</span></td>';
						}

						html += '<td class="fs-0 operationLeft">';
						// html += '<a href="' + __URL(ADMINMAIN + '/express/expresstemplate?co_id=' + data["data"][i]["co_id"]) + '">打印模板</a>&nbsp;&nbsp;';
						// html += '<a href="' + __URL(ADMINMAIN + '/express/updateexpresscompany?co_id=' + data["data"][i]["co_id"]) + '">修改</a><br/>';
						if (curr.shop_id == shop_id && curr.website_id == website_id) {
							html += '<a class="btn-operation disabled-company" href="javascript:;" data-co-id="' + curr.co_id + '">禁用</a> ';
							html += '<a class="btn-operation" href="' + __URL(ADMINMAIN + '/express/freighttemplatelist?co_id=' + curr.co_id) + '">运费模板</a> ';
						} else {
							html += '<a class="btn-operation able-company" href="javascript:;" data-co-id="'+ curr.co_id+'">启用</a> ';
						}
						html += '</tr>';
					}
				} else {
					html += '<tr align="center"><td colspan="4" class="h-200">暂无符合条件的数据记录</td></tr>';
				}
				$("#list").html(html);
				utilAdmin.tips();
				utilAdmin.page(".M-box3", data['total_count'], data["page_count"], page_index, LoadingInfo);
			}
		});
	}

	//全选
	function CheckAll(event) {
		var checked = event.checked;
		$(".style0list tbody input[type = 'checkbox']").prop("checked", checked);
	}

    $("body").on("click",".search_to",function(){
        LoadingInfo(1);
    })

  })
</script>
{/block}